package com.itqf.quartz01;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

/**
 * @Description: quartz核心对象的构建都是....build();
 * JobDetail  任务
 * Trigger  触发器
 * Scheduler  调度器
 *
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2021/1/26
 * @Time: 上午9:48
 */
public class QuartzDemo01 {

    public  static  void  main(String[]args){
        //1.创建一个JobDetail  任务的描述
        /**
         * 订单半小时未支付  -->取消
         * 每个月定时扣话费
         * 信用卡定时还款
         */
        //Class<? extends Job> jobClass
        JobDetail jobDetail = JobBuilder.newJob(MyJob.class).
                withIdentity("myJob").build();

        //2.创建Trigger  触发器  触发任务执行
        //.withSchedule(SimpleScheduleBuilder.simpleSchedule() 简单触发器
        // .withIntervalInSeconds(3).repeatForever()) 重复周期  重复次数

        Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("myTrigger")
                .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                        .withIntervalInSeconds(5).repeatForever())
                .startNow()//立即开始
                .build();

        //3.创建调度器
        //3.1 创建工厂
        SchedulerFactory schedulerFactory = new StdSchedulerFactory();
        //3.2 构建调度器
        try {
            Scheduler scheduler = schedulerFactory.getScheduler();

        //4.调度器注册任务和触发器
        scheduler.scheduleJob(jobDetail,trigger);

        //5.开启任务
            scheduler.start();

        } catch (SchedulerException e) {
            e.printStackTrace();
        }


    }

}
